<template>
  <el-dialog
    title="参会人员列表"
    :visible.sync="visible"
    top="10vh"
    width="600px"
    class="dialog-sponsor"
    append-to-body
    :close-on-click-modal="false"
    :before-close="handleCancel"
  >
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="name" label="名字" align="left"></el-table-column>
      <el-table-column label="操作" align="left">
        <template slot-scope="scope">
          <el-button type="text" @click="editItem(scope.row)">编辑</el-button>
          <el-button type="text" @click="delItem(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
import {listOrganizer, delOrganizer} from '@/api/meetingManagement/organizer'

export default {
  name: "DialogList",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: () => ({})
    }
  },
  watch: {
    visible: {
      handler(val) {
      }
    }
  },
  data() {
    return {
      tableData: []
    }
  },
  methods: {
    initData() {
      listOrganizer().then(res => {
        if (res.code === 200) {
          this.tableData = res.rows || []
        }
      })
    },
    handleCancel() {
      this.$emit("update:visible", false);
    },
    editItem(row) {
      console.log(row)
      this.$emit("editFun", row);
    },
    delItem(row) {
      console.log(row)
      this.$confirm("你确定删除该条参会人员吗?", "", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          const id = row.id
          const {code, msg} = await delOrganizer(id)
          if (code == 200) {
            this.$message.success(`删除成功！`)
            this.initData()
            this.$emit("refresh");
          } else {
            this.$message.error(msg)
          }
        })
        .catch(() => {
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog-sponsor {
  ::v-deep {
    .el-dialog__body {
      padding: 10px 20px;
    }
  }

  &__footer {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
  }
}
</style>
